package com.itheima.api.treemap.demo03;

import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class String_TreeMap {

    public static void main(String[] args) {

        String s = "aababcabcdabcde" ;
        char[] chars = s.toCharArray();
        TreeMap<Character, Integer> treeMap = new TreeMap<>();
        for (Character c : chars){
            Integer integer = treeMap.get(c);
            if (integer == null){
                treeMap.put(c, 1);
            } else {
                integer++;
                treeMap.put(c, integer);
            }
        }
//        treeMap.forEach((key, value) -> System.out.print(key + "(" + value + ")"));

        StringBuilder sb = new StringBuilder();
        Set<Map.Entry<Character, Integer>> entrySet = treeMap.entrySet();
        for (Map.Entry<Character, Integer> entry : entrySet){
            sb.append(entry.getKey()).append("(").append(entry.getValue()).append(")");
        }
        String toString = sb.toString();
        System.out.println(toString);

    }
}
